﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文本框焦点</title>
    <script type="text/javascript">
        function changeBg(){
            var obj = document.getElementById("tx2");
            obj.style.backgroundColor="yellow";
        }
        function changeBg1(){
            var obj = document.getElementById("tx2");
            obj.style.backgroundColor="red";
        }
    </script>
</head>
<body>
<input type="text" id="tx1"><br>
<input type="text" id="tx2" style="background-color:#FF0000" 
       onFocus="changeBg()" onBlur="changeBg1()">
</body>
</html>